import java.io.File;
import java.io.IOException;

import javax.sound.sampled.*;

public class MySound {

	private String url;
	private AudioInputStream stream1;
	private Clip clip1;

	public MySound(String url) {
		this.url = url;
		try {
			// get first sound clip
			stream1 = AudioSystem.getAudioInputStream(new File(url));
			
			clip1 = AudioSystem.getClip();
			clip1.open(stream1);

		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	public void playLoop() throws LineUnavailableException, IOException {
		clip1.setFramePosition(0);
		clip1.start();
	}

	// stopLoop inteso per fermare completamente il loop, non metterlo solo in pausa
	public void stopLoop() throws IOException {
		clip1.stop();
		clip1.flush();
//		closeSound();
	}

	public void closeSound() throws IOException {
		clip1.stop();
		clip1.flush();
		clip1.close();
		stream1.close();
	}
}
